var countdown=60;
function set_time(obj) {
    var str = $("#user_phone").val();
    if (str== "" ){
        $("#user_phone").placeholder="手机号不能为空！";
        flag=0;
        document.getElementById("user_phone".placeholder.color="red");
    }else {
        var re = /^1\d{10}$/;
        if (!re.test(str)) {
            flag=1;
        }
        else{
            flag=2;
        }
    }
    if(flag==0){
        $("#user_phone").value = "";
        $("#user_phone").placeholder = "手机号不能为空！";
    }
    if(flag==1){
        document.getElementById("phoneLabel").style.display = "inline";
    }
    if(flag==2){
        var userAccount=$("#user_phone").val();
        $.post("/password/captcha", "userAccount="+userAccount, function (data,status) {
            if (data==1){
                timeSt(obj);
            }else if(data==2) {
                alert("该用户未注册");
            }
        });

    }
}

function timeSt(obj) {
    if (countdown == 0) {
        obj.removeAttribute("disabled");
        obj.value="获取验证码";
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value="重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function() {
            timeSt(obj)
        }
        ,1000)

}


var flag;
var phoneNum;
function reg1(str){
    if (str== "" ){
        user_phone.placeholder="手机号不能为空！";
        flag=0;
        document.getElementById("user_phone".placeholder.color="red");
    }
    else{
        var re = /^1\d{10}$/;
        if (!re.test(str)) {
            flag=1;
        }
        else{
            flag=2;
        }
    }
    if(flag==0){
        user_phone.value = "";
        user_phone.placeholder = "手机号不能为空！";
    }
    if(flag==1){
        document.getElementById("phoneLabel").style.display = "inline";
    }
    if(flag==2){
        phoneNum=document.getElementById("user_phone").value;
        var captcha = $("#captcha").val();
        $.post("/alter/password1","captcha="+captcha+"&&userAccount="+phoneNum,function (data,status) {
            if (data==0){
                window.location.href = "Change_Password2.html";
            } else {
                alert("验证信息不通过");
            }
        });
    }
}

function phone_reset(){
    user_phone.placeholder="请输入11位手机号";
}
function password_reset(){
    user_password.placeholder="密码(6~16位，字母开头，数字，下划线)";
}

var flag1;
function checkMobile ( str,str1 ) {
    if (str== "" ){
        if (str1== "" ){
            user_phone.placeholder="手机号不能为空！";
            flag1=0;
            document.getElementById("user_phone".placeholder.color="red");
        }
        else{
            var re = /^1\d{10}$/;
            if (!re.test(str1)) {
                flag1=1;
            }
            else{
                flag1=2;
            }
        }
        if(flag1==0){
            user_phone.value = "";
            user_phone.placeholder = "手机号不能为空！";
        }
        if(flag1==1){
            document.getElementById("phoneLabel").style.display = "inline";
        }
        if(flag1==2){
            phoneNum=document.getElementById("user_phone").value;
            document.getElementById("phoneLabel").style.display = "none";
            document.getElementById("next").removeAttribute("disabled");
            document.getElementById("next").style.background="#0077E6";
        }
    }

}

function checkPassword(str){
    if (str== "" ){
        user_password.placeholder="密码不能为空！";
    }
    else {
        var re = /^[a-zA-Z]\w{5,16}$/;
        if (!re.test(str)) {
            user_password.value = "";
            user_password.placeholder = "密码不合法！";
        }
    }
}

var userAccount;
var password;
var userName;
var identify;
function checkSame(){
    var p1=document.getElementById("user_password").value;
    var p2=document.getElementById("user_password_settled").value;
    if(p1!=p2){
        document.getElementById("passwordLabel").style.display = "inline";
    }
    if(p1==p2&&p1!="") {

        $.ajax({
            type:'post',
            async:true,
            dataType:'json',
            url:'/alter/password2' ,//接口
            data:{"userPassword":p1},
            success:function (data) {
                if(data==1)//与返回值比较，判断
                {
                    alert('修改成功！');
                    window.location.href = "Self_Information.jsp";
                }else{
                    alert('修改失败！请仔细核实！')
                }
            }
        });

    }

}
